package com.project.weather.controller;

import com.project.weather.aspectj.Log;
import com.project.weather.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import io.swagger.annotations.*;
import com.project.weather.common.PageBean;
import com.project.weather.common.AResultCode;
import com.project.weather.common.ResultMap;
import com.project.weather.pojo.UserBean;
import com.project.weather.service.UserService;

/**
 *<p>Title:UserController.java</p>
 *<p>Description:用户信息表 Action</p>
 *@author xxx
 *@version 1.0
 *@Automatically generate by Coder in 2021-12-21 16:07
 */
@RestController
@RequestMapping(name="用户信息表", value="/user/")
@Api(tags = {"用户信息表 Api 接口文档"})
public class UserController {
	private static final Logger log = LoggerFactory.getLogger(UserController.class);
	@Autowired
	private UserService userService;

	@ApiOperation(value="新增接口")
	@Log(title = "用户信息", businessType = BusinessType.INSERT)
	@Transactional
	@RequestMapping(name="新增接口",value="insert.json",method = RequestMethod.POST)
	public ResultMap<AResultCode, UserBean> insert(@ApiParam(value = "对象数据", required = true) @RequestBody UserBean bean){
		return userService.insert(bean);
	}

	@ApiOperation(value="修改接口")
	@Log(title = "用户信息", businessType = BusinessType.UPDATE)
	@Transactional
	@RequestMapping(name="修改接口",value="update.json",method = RequestMethod.POST)
	public ResultMap<AResultCode, UserBean> update(@ApiParam(value = "对象数据", required = true) @RequestBody UserBean bean){
		return userService.update(bean);
	}

	@ApiOperation(value="删除接口")
	@Log(title = "用户信息", businessType = BusinessType.DELETE)
	@ApiImplicitParam(name = "user_id", value = "主键ID", required = true, paramType = "query")
	@RequestMapping(name="删除接口",value="delete.json",method = RequestMethod.GET)
	@Transactional
	public ResultMap<AResultCode, UserBean> delete(@RequestParam("user_id") String user_id){
		return userService.delete(user_id);
	}

	@ApiOperation(value="分页查询列表接口")
	@Log(title = "用户信息", businessType = BusinessType.LIST)
	@RequestMapping(name="分页查询列表接口",value="pageList.json",method = RequestMethod.POST)
	public ResultMap<AResultCode, PageBean<UserBean>> pageList(@ApiParam(value = "分页对象数据", required = true) @RequestBody PageBean<UserBean> pb){
		pb.init(pb,UserBean.class);	//需要调用init，将页面传来的json条件转换为bean
		return userService.pageList(pb);
	}

	@ApiOperation(value="查询所有数据接口")
	@Log(title = "用户信息", businessType = BusinessType.LIST)
	@RequestMapping(name="查询所有数据接口",value="list.json",method = RequestMethod.POST)
	public ResultMap<AResultCode, List<UserBean>> list(@ApiParam(value = "对象数据", required = true) @RequestBody(required = false) UserBean bean){
		return userService.list(bean);
	}

	@ApiOperation(value="根据主键获取数据接口")
	@Log(title = "用户信息", businessType = BusinessType.LIST)
	@ApiImplicitParam(name = "user_id", value = "主键ID", required = true, paramType = "query")
	@RequestMapping(name="根据主键获取数据接口",value="get.json",method = RequestMethod.GET)
	public ResultMap<AResultCode, UserBean> get(String user_id){
		return userService.get(user_id);
	}

	@ApiOperation(value="禁用用户接口")
	@Log(title = "禁用用户", businessType = BusinessType.FORBIDDEN)
	@ApiImplicitParam(name = "user_id", value = "主键ID", required = true, paramType = "query")
	@RequestMapping(name="禁用用户接口",value="forbid.json",method = RequestMethod.GET)
	@Transactional
	public ResultMap<AResultCode, UserBean> forbid(@RequestParam("user_id") String user_id){
		return userService.forbid(user_id);
	}

	@ApiOperation(value="启用用户接口")
	@Log(title = "启用用户", businessType = BusinessType.RMFORBIDDEN)
	@ApiImplicitParam(name = "user_id", value = "主键ID", required = true, paramType = "query")
	@RequestMapping(name="启用用户接口",value="start.json",method = RequestMethod.GET)
	@Transactional
	public ResultMap<AResultCode, UserBean> start(@RequestParam("user_id") String user_id){
		return userService.start(user_id);
	}

	@ApiOperation(value="解除管理员权限接口")
	@Log(title = "解除管理员权限", businessType = BusinessType.DEGRANT)
	@ApiImplicitParam(name = "user_id", value = "主键ID", required = true, paramType = "query")
	@RequestMapping(name="解除管理员权限接口",value="reliveAdmin.json",method = RequestMethod.GET)
	@Transactional
	public ResultMap<AResultCode, UserBean> reliveAdmin(@RequestParam("user_id") String user_id){
		return userService.reliveAdmin(user_id);
	}

	@ApiOperation(value="授予管理员权限接口")
	@Log(title = "授予管理员权限", businessType = BusinessType.GRANT)
	@ApiImplicitParam(name = "user_id", value = "主键ID", required = true, paramType = "query")
	@RequestMapping(name="授予管理员权限接口",value="grantAdmin.json",method = RequestMethod.GET)
	@Transactional
	public ResultMap<AResultCode, UserBean> grantAdmin(@RequestParam("user_id") String user_id){
		return userService.grantAdmin(user_id);
	}


}